home *** CD-ROM | disk | FTP | other *** search
/ PC Open 107 / PC Open 107 CD 1.bin / CD1 / INTERNET / COPIA SITI / Getleft / getleft-setup-notcl.exe / {app} / scripts / getLog.tcl < prev    next >
Encoding:
Text File  |  2004-05-21  |  46.8 KB  |  1,393 lines

  1. ################################################################################
  2. ################################################################################
  3. ##                             getLog.tcl
  4. ################################################################################
  5. ################################################################################
  6. ## Defines Getleft's log windows.
  7. ################################################################################
  8. ################################################################################
  9. ## (c) 2001-2004 AndrΘs Garcφa Garcφa. fandom@retemail.es
  10. ## You may distribute the contents of this file under the terms of the GPL v2
  11. ################################################################################
  12. ################################################################################
  13.  
  14. namespace eval getLog {
  15.  
  16. ################################################################################
  17. # DefineTaskbarButtons
  18. #    Defines the buttons in the taskbar.
  19. #
  20. # Parameters
  21. #    The frame for the buttons.
  22. ################################################################################
  23. proc DefineTaskbarButtons {frame} {
  24.     global   labelDialogs labelMenus
  25.     variable siteTaskbar
  26.     variable siteLog
  27.  
  28.     set siteTaskbar(start)  [button $frame.start   -image $iconNS::iconImages(start) \
  29.             -relief flat -bd 1 -command {
  30.                 getLog::UrlLogDownload [getLog::UrlLogSelectedUrl]
  31.             }]
  32.     ::BalloonHelp::set_balloon $siteTaskbar(start)  $labelDialogs(start)
  33.  
  34.     set siteTaskbar(update) [button $frame.update -image $iconNS::iconImages(update) \
  35.             -relief flat -bd 1 -command {
  36.                 getLog::UrlLogUpdate [getLog::UrlLogSelectedUrl]
  37.             }]
  38.     ::BalloonHelp::set_balloon $siteTaskbar(update) $labelDialogs(update)
  39.  
  40.     set siteTaskbar(queue)  [button $frame.queue -image $iconNS::iconImages(queue)   \
  41.             -relief flat -bd 1 -command {
  42.                 getLog::UrlLogQueue [getLog::UrlLogSelectedUrl]    
  43.             }]
  44.     ::BalloonHelp::set_balloon $siteTaskbar(queue)  $labelDialogs(queue)
  45.  
  46.     set siteTaskbar(conf)  [button $frame.conf  -image $iconNS::iconImages(conf)     \
  47.             -relief flat -bd 1 -command {
  48.                 getLog::UrlLogChangeOptions [getLog::UrlLogSelectedUrl]    
  49.             }]
  50.     ::BalloonHelp::set_balloon $siteTaskbar(conf)   $labelDialogs(options)
  51.  
  52.     set siteTaskbar(exit) [button $frame.exit  -image $iconNS::iconImages(exit)      \
  53.             -relief flat -bd 1 -command "wm withdraw $siteLog(toplevel)"]
  54.     ::BalloonHelp::set_balloon $siteTaskbar(exit)   $labelDialogs(exit)
  55.  
  56.     foreach {name path} [array get siteTaskbar] {
  57.         bindtags $path "[bindtags $path] logTaskIcon"
  58.     }
  59.     bind logTaskIcon <<ButtonRaise>> {
  60.         %W configure -relief raised
  61.     }
  62.     bind logTaskIcon <<ButtonFlat>> {
  63.         %W configure -relief flat
  64.     }
  65.  
  66.     pack $siteTaskbar(start) $siteTaskbar(update) $siteTaskbar(queue) $siteTaskbar(conf) \
  67.             -side left
  68.     pack $siteTaskbar(exit) -side right
  69.  
  70.     return
  71. }
  72.  
  73. ################################################################################
  74. # ActivateSiteTaskbarButtons
  75. #    Activates or disables the buttons in the taskbar depending on whether
  76. #    there is a row selected.
  77. ################################################################################
  78. proc ActivateSiteTaskbarButtons {} {
  79.     variable siteTaskbar
  80.     variable siteLog
  81.  
  82.     set anchor [$siteLog(listbox) curselection]
  83.     if {$anchor==""} {
  84.         $siteTaskbar(start)  configure -state disabled
  85.         $siteTaskbar(update) configure -state disabled
  86.         $siteTaskbar(queue)  configure -state disabled
  87.         $siteTaskbar(conf)   configure -state disabled
  88.     } else {
  89.         $siteTaskbar(start)  configure -state normal
  90.         $siteTaskbar(update) configure -state normal
  91.         $siteTaskbar(queue)  configure -state normal
  92.         $siteTaskbar(conf)   configure -state normal
  93.     }
  94.     return
  95. }
  96.  
  97. ################################################################################
  98. # UrlLogWrite
  99. #    Writes the file with the urls in the log, the file will be saved in the
  100. #    dirGetleft(conf) directory with the name getLog.log.
  101. ################################################################################
  102. proc UrlLogWrite {} {
  103.     variable urlLog
  104.     global dirGetleft getleftState
  105.  
  106.     set urlLogFile [file join $dirGetleft(conf) getLog.log]
  107.     if {(![info exists urlLog(urlList)])||([llength $urlLog(urlList)]==0)} {
  108.         catch {file delete $urlLogFile}
  109.         return
  110.     }
  111.     if {$getleftState(os)=="win"} {
  112.         if {[file exists $urlLogFile]} {
  113.             # It seems that Win2K doesn't like to read hidden files,
  114.             # so I unhide it for a couple of seconds.
  115.             file attributes $urlLogFile -hidden 0
  116.         }
  117.     } 
  118.  
  119.     set handle [open "$urlLogFile" w]
  120.  
  121.     puts $handle "# Log of the sites downloaded by Getleft."
  122.     puts $handle "# This file is generated automatically, please do not edit."
  123.     puts $handle "\n\n\n"
  124.  
  125.     puts $handle "set urlLog(urlList) [list $urlLog(urlList)]"
  126.     puts $handle "\n\n"
  127.     foreach url $urlLog(urlList) {
  128.         regsub -all {\s} $url    {\\&} urlTmp
  129.         regsub -all {\;} $urlTmp {\\;} urlTmp
  130.         catch {
  131.             puts $handle "set urlLog($urlTmp,localDir) \"$urlLog($url,localDir)\""
  132.             puts $handle "set urlLog($urlTmp,date)     $urlLog($url,date)"
  133.             puts $handle "set urlLog($urlTmp,options)  [list $urlLog($url,options)]"
  134.             puts $handle "set urlLog($urlTmp,keep)     $urlLog($url,keep)"
  135. #           puts $handle "set urlLog($urlTmp,encoding) $urlLog($url,encoding)"
  136.         }
  137.     }
  138.     puts $handle "\n\n"
  139.     close $handle
  140.  
  141.     if {$getleftState(os)=="win"} {
  142.         file attributes $urlLogFile -hidden 1
  143.     } else {
  144.         file attributes $urlLogFile -permissions 0600
  145.     }
  146.  
  147.     return
  148. }
  149.  
  150. ################################################################################
  151. # UrlLogRead
  152. #    Reads the file with the urls in the log, the file will be saved in the
  153. #    dirGetleft(conf) directory with the name getLog.log.
  154. #
  155. # Side effect
  156. #    The namespace variable urlLog will be set in all its glory.
  157. ################################################################################
  158. proc UrlLogRead {} {
  159.     variable urlLog
  160.     global dirGetleft getleftState
  161.  
  162.     set urlLogFile [file join $dirGetleft(conf) getLog.log]
  163.     if {[file exists $urlLogFile]} {
  164.         if {$getleftState(os)=="win"} {
  165.             file attributes $urlLogFile -hidden 0
  166.         }
  167.         source $urlLogFile
  168.         if {$getleftState(os)=="win"} {
  169.             file attributes $urlLogFile -hidden 1
  170.         }
  171.     } else {
  172.         set urlLog(urlList) ""
  173.     }
  174.  
  175.     return
  176. }
  177.  
  178. ################################################################################
  179. # UrlLogGetIndex
  180. #   When the user clicks in the url list, this procedure takes care of selecting
  181. #   the nearest entry and returns its index.
  182. #
  183. # Parameters
  184. #   win: window where you clicked.
  185. #   y: the coordinate where you did it
  186. #
  187. # Returns
  188. #   The index of the url, or -1 if the is none to return
  189. ################################################################################
  190. proc UrlLogGetIndex {win y} {
  191.     
  192.     set ::tablelist::win [winfo parent $win]
  193.     set ::tablelist::y [expr "$y + [winfo y $win]"]
  194.     if {[winfo exists $::tablelist::win]} {
  195.         set index [$::tablelist::win nearest $::tablelist::y]
  196.         if {$index!=-1} {
  197.             if {[catch {tkListboxBeginSelect $::tablelist::win $index}]} {
  198.                 tk::ListboxBeginSelect $::tablelist::win $index
  199.             }
  200.         }
  201.         return $index
  202.     }
  203.     return -1
  204. }
  205.  
  206. ################################################################################
  207. # UrlLogUrlIndex
  208. #   Given an Url this procedure returns its index in the listbox.
  209. #
  210. # Parameters
  211. #   url: The url to search for.
  212. #
  213. # Returns
  214. #   The index of the url, or -1 if the is none to return
  215. ################################################################################
  216. proc UrlLogUrlIndex {url} {
  217.     variable siteLog
  218.     variable urlLog
  219.  
  220.     if {(![info exists siteLog(listbox)])||(![winfo exists $siteLog(listbox)])} {
  221.         return -1
  222.     }
  223.  
  224.     set rowNumber [$siteLog(listbox) size]
  225.     for {set i 0} {$i<$rowNumber} {incr i} {
  226.         set site [$siteLog(listbox) cellcget $i,0 -text]
  227.         if {[string match $url $site]} {
  228.             return $i
  229.         }
  230.     }
  231.  
  232.     return -1
  233. }
  234.  
  235. ################################################################################
  236. # UrlLogEnter
  237. #    Enters one Url and its data into the urlLog. This procedure is invoked
  238. #    after the site has been downloaded.
  239. #
  240. # Parameters
  241. #    url: The url to enter.
  242. #    dir: The directory where it has been saved.
  243. #    options: A list with the options for downloading the site.
  244. #
  245. # Side effect: To begin with the keep bit will be set to '0'.
  246. ################################################################################
  247. proc UrlLogEnter {url dir options} {
  248.     variable urlLog
  249.     variable siteLog
  250.  
  251.     set oldIndex [lsearch $urlLog(urlList) $url]
  252.     if {$oldIndex==-1} {
  253.         set urlNumber [llength $urlLog(urlList)]
  254.         if {$urlNumber>=100} {
  255.             for {set i 0} {$i<$urlNumber} {incr i} {
  256.                 set urlTmp [lindex $urlLog(urlList) $i]
  257.                 if {(![info exists urlLog($urlTmp,keep)])||($urlLog($urlTmp,keep)==0)} {
  258.                     UrlLogRemove $urlTmp
  259.                     break
  260.                 }
  261.             }
  262.             if {$i==$urlNumber} {
  263.                 return
  264.             }
  265.         }
  266.         lappend urlLog(urlList) $url
  267.     }
  268.  
  269.     set urlLog($url,localDir) "$dir"
  270.     set urlLog($url,date)     [clock seconds]
  271.     set urlLog($url,options)  $options
  272.     if {![info exists urlLog($url,keep)]} {
  273.         set urlLog($url,keep) 0
  274.     }
  275.  
  276.     if {([info exists siteLog])&&([winfo exists $siteLog(listbox)])} {
  277.         set oldIndex [UrlLogUrlIndex $url]
  278.         $siteLog(listbox) delete $oldIndex
  279.         if {$oldIndex==-1} {
  280.             GetLogWindowRow $url $dir
  281.         } else {
  282.             GetLogWindowRow $url $dir $oldIndex
  283.         }
  284.     }
  285.     return
  286. }
  287.  
  288. ################################################################################
  289. # UrlLogSelectedUrl
  290. #   When the user clicks on the icons, this procedure is used to know the url
  291. #   of the row that was selected at the time.
  292. #
  293. # Returns
  294. #   The url or an empty string if no row is selected
  295. ################################################################################
  296. proc UrlLogSelectedUrl {} {
  297.     variable siteLog
  298.  
  299.     set anchor [$siteLog(listbox) curselection]
  300.     if {[catch {$siteLog(listbox) cellcget $anchor,0 -text} url]} {
  301.         return
  302.     }
  303.  
  304.     return $url
  305. }
  306.  
  307. ################################################################################
  308. # UrlLogDownload
  309. #   Starts downloading one of the sites in the log.
  310. #
  311. # Parameters
  312. #   url: The site we are talking about.
  313. ################################################################################
  314. proc UrlLogDownload {url} {
  315.     variable urlLog
  316.     global   getleftState
  317.  
  318.     if {$url==""} return
  319.  
  320.     PutUrlInQueue $url "$urlLog($url,localDir)" "$urlLog($url,options)"
  321.  
  322.     if {$getleftState(downloading)==0} {
  323.         AutomaticDownload $url                
  324.     }
  325.  
  326.     return
  327. }
  328.  
  329. ################################################################################
  330. # UrlLogUpdate
  331. #   Starts updating one of the sites in the log, actually it only makes sure
  332. #   the 'update' option is set before passing it the 'UrlLogDownload'
  333. #
  334. # Parameters
  335. #   url: The site we are talking about.
  336. ################################################################################
  337. proc UrlLogUpdate {url} {
  338.     variable urlLog
  339.  
  340.     if {$url==""} return
  341.  
  342.     set optionsTmp $urlLog($url,options)
  343.  
  344.     regsub {update [0-1]} "$urlLog($url,options)" \
  345.            {update 1}       urlLog($url,options)
  346.  
  347.     UrlLogDownload $url                
  348.  
  349.     set urlLog($url,options) $optionsTmp
  350.  
  351.     return
  352. }
  353.  
  354. ################################################################################
  355. # UrlLogQueue
  356. #   Puts the url and its data into Getleft's url queue for future downloading.
  357. #
  358. # Parameters
  359. #   url: The site we are talking about.
  360. ################################################################################
  361. proc UrlLogQueue {url} {
  362.     variable urlLog
  363.  
  364.     if {$url==""} return
  365.  
  366.     PutUrlInQueue $url "$urlLog($url,localDir)" "$urlLog($url,options)"
  367.  
  368.     return
  369. }
  370.  
  371. ################################################################################
  372. # UrlLogChangeOptions
  373. #   Changes the options for downloading an URL in the urlList.
  374. #
  375. # Parameters
  376. #   url: The site we are talking about.
  377. ################################################################################
  378. proc UrlLogChangeOptions {url} {
  379.     variable urlLog
  380.  
  381.     if {$url==""} return
  382.  
  383.     array set ::downOptionsTemp $urlLog($url,options)
  384.     set done [::Opciones::ChooseOptions ::downOptionsTemp]
  385.     if {$done==1} {
  386.         set urlLog($url,options) [array get ::downOptionsTemp]
  387.     }
  388.     return
  389. }
  390.  
  391. ################################################################################
  392. # UrlLogChangeDir
  393. #   Changes the directory to store the download.
  394. #
  395. # Parameters
  396. #   url: The site we are talking about.
  397. ################################################################################
  398. proc UrlLogChangeDir {url} {
  399.     variable urlLog
  400.     variable siteLog
  401.  
  402.     set baseDir [Dialogos::SelectDirectory [file dirname $urlLog($url,localDir)]]
  403.     if {$baseDir!=""} {
  404.         set urlLog($url,localDir) $baseDir
  405.         set index [UrlLogUrlIndex $url]
  406.         $siteLog(listbox) cellconfigure $index,1 -text [file nativename $baseDir]
  407.     }
  408.  
  409.     return
  410. }
  411.  
  412. ################################################################################
  413. # UrlLogLaunchLocalCopy
  414. #    If the local copy of the site is still present, this will launch the 
  415. #    browser and open it. 
  416. #
  417. # Parameters
  418. #    url: The downloaded url.
  419. #    dir: The directory in which the site was saved.
  420. ################################################################################
  421. proc UrlLogLaunchLocalCopy {url dir} {
  422.     global labelTitles labelMessages
  423.     variable siteLog
  424.  
  425.     set localFile [Commands::UrlToFile $url $dir]
  426.  
  427.     if {![file exists $localFile]} {
  428.         tk_messageBox -type ok -icon error -message $labelMessages(noFile) \
  429.                 -title $labelTitles(error) -parent $siteLog(toplevel)
  430.         return
  431.     }
  432.     if {[file isdirectory $localFile]} {
  433.         set tmpFileI  [file join $localFile index.html]
  434.         set tmpFileII [file join $localFile index.htm]
  435.         if {[file exists $tmpFileI]} {
  436.             set localFile $tmpFileI
  437.         } elseif {[file exists $tmpFileII]} {
  438.             set localFile $tmpFileII
  439.         }
  440.     }
  441.     Ayuda::InvokeBrowser $localFile $getLog::siteLog(toplevel)
  442.  
  443.     return
  444. }
  445.  
  446. ################################################################################
  447. # UrlLogRemove
  448. #    Removes one Url from the log 
  449. #
  450. # Parameters
  451. #    url: The url to remove.
  452. ################################################################################
  453. proc UrlLogRemove {url} {
  454.     variable urlLog
  455.     variable siteLog
  456.  
  457.     set index [lsearch $urlLog(urlList) $url]
  458.     if {$index==-1} {
  459.         return
  460.     }
  461.  
  462.     set urlLog(urlList) [lreplace $urlLog(urlList) $index $index]
  463.     catch {unset urlLog($url,locaDir)}
  464.     catch {unset urlLog($url,date)}
  465.     catch {unset urlLog($url,options)}
  466.     catch {unset urlLog($url,keep)}
  467.  
  468.     set index [UrlLogUrlIndex $url]
  469.     if {$index==-1} {
  470.         return
  471.     }
  472.     $siteLog(listbox) delete $index
  473.     ActivateSiteTaskbarButtons
  474.  
  475.     return
  476. }
  477.  
  478. ################################################################################
  479. # UrlLogRightMenuKey
  480. #   This procedure is invoked when the user presses the menu key in the log 
  481. #   window, it collect the info to make a context menu pop up with the
  482. #   appropiate options
  483. #
  484. # Parameters
  485. #   X,Y: THe coordinates for the pop up menu.
  486. ################################################################################
  487. proc UrlLogMenuKey {X Y} {
  488.     variable siteLog
  489.  
  490.     UrlLogContextMenu [$siteLog(listbox) index active] $X $Y
  491.  
  492.     return
  493. }
  494.  
  495. ################################################################################
  496. # UrlLogRightClick
  497. #   This procedure is invoked when the user right-clicks in the multicolumn
  498. #   list with the sites, it makes a context menu pop up with the
  499. #   appropiate options
  500. #
  501. # Parameters
  502. #   win: window where you right-clicked.
  503. #   y,x: the coordinates where you did it for the tablelist widget.
  504. #   X,Y: and for the pop up menu.
  505. ################################################################################
  506. proc UrlLogRightClick {win x y X Y} {
  507.     variable siteLog
  508.  
  509.     set index [UrlLogGetIndex $win $y]
  510.     if {$index==-1} return
  511.  
  512.     $siteLog(listbox) activate $index
  513.     UrlLogContextMenu $index $X $Y
  514.  
  515.     return
  516. }
  517.  
  518. ################################################################################
  519. # UrlLogContextMenu
  520. #   This procedure takes care of showing the context menu in the Site Log 
  521. #   window.
  522. #
  523. # Parameters
  524. #   index: Row about which the menu will be.
  525. #   X,Y: Coordinates for the pop up menu.
  526. ################################################################################
  527. proc UrlLogContextMenu {index X Y} {
  528.     variable siteLog
  529.     variable siteMenus
  530.  
  531.     ActivateSiteTaskbarButtons
  532.  
  533.     set url [$siteLog(listbox) cellcget $index,0 -text]
  534.     set dir [$siteLog(listbox) cellcget $index,1 -text]
  535.  
  536.     $siteMenus(rightClick) entryconfigure 0                                  \
  537.             -command "getLog::UrlLogDownload [list $url]"
  538.     $siteMenus(rightClick) entryconfigure 1                                  \
  539.             -command "getLog::UrlLogUpdate   [list $url]"
  540.     $siteMenus(rightClick) entryconfigure 3                                  \
  541.             -command "getLog::UrlLogQueue    [list $url]"
  542.     $siteMenus(rightClick) entryconfigure 5                                  \
  543.             -command "getLog::UrlLogChangeOptions [list $url]"
  544.     $siteMenus(rightClick) entryconfigure 6                                  \
  545.             -command "getLog::UrlLogChangeDir [list $url]"
  546.     $siteMenus(rightClick) entryconfigure 7                                  \
  547.             -variable getLog::urlLog($url,keep)
  548.     $siteMenus(rightClick) entryconfigure 9                                  \
  549.             -command "clipboard clear
  550.                       clipboard append [list $url]"
  551.     $siteMenus(rightClick) entryconfigure 11                                 \
  552.             -command "Ayuda::InvokeBrowser $url $getLog::siteLog(toplevel)"
  553.     $siteMenus(rightClick) entryconfigure 12                                 \
  554.             -command "getLog::UrlLogLaunchLocalCopy [list $url] [list $dir]"
  555.     $siteMenus(rightClick) entryconfigure 14                                 \
  556.             -command "getLog::UrlLogRemove [list $url]"
  557.  
  558.     tk_popup $siteMenus(rightClick) $X $Y
  559.  
  560.     return
  561. }
  562.  
  563. ################################################################################
  564. # UrlLogDoubleClick
  565. #   This procedure is invoked when the user double-clicks in the multicolumn
  566. #   list with the sites, it makes a context menu pop up with the
  567. #   appropiate options
  568. #
  569. # Parameters
  570. #   win: window where you right-clicked.
  571. #   y,x: the coordinates where you did it for the tablelist widget.
  572. #   X,Y: and for the pop up menu.
  573. ################################################################################
  574. proc UrlLogDoubleClick {win x y X Y} {
  575.     variable siteLog
  576.     variable siteMenus
  577.     variable urlLog
  578.  
  579.     set index [UrlLogGetIndex $win $y]
  580.     if {$index==-1} return
  581.  
  582.     ActivateSiteTaskbarButtons
  583.  
  584.     set url [$siteLog(listbox) cellcget $index,0 -text]
  585.  
  586.     $siteMenus(doubleClick) entryconfigure 0                         \
  587.             -command "getLog::UrlLogDownload [list $url]"
  588.     $siteMenus(doubleClick) entryconfigure 1                         \
  589.             -command "getLog::UrlLogUpdate   [list $url]"
  590.  
  591.     tk_popup $siteMenus(doubleClick) $X $Y
  592.  
  593.     return
  594. }
  595.  
  596. ###############################################################################
  597. # GetLogSortUrl
  598. #    This procedure is used to sort the list depending on the url.
  599. #
  600. # Parameter:
  601. #    firstUrl, secondUrl: The urls to compare
  602. #
  603. # Returns:
  604. #     '-1', '0' or '1' if the first url is 'smaller' than, equal to or 
  605. #     'greater' than the second.
  606. ###############################################################################
  607. proc GetLogSortUrl {firstUrl secondUrl} {
  608.     global labelMonths
  609.  
  610.     regexp {(?:://)(.*)} $firstUrl  nada firstUrl
  611.     regexp {(?:://)(.*)} $secondUrl nada secondUrl
  612.  
  613.     set firstUrl  [string tolower $firstUrl]
  614.     set secondUrl [string tolower $secondUrl]
  615.  
  616.     if {$firstUrl<$secondUrl} {
  617.         return -1
  618.     } elseif {$firstUrl==$secondUrl} {
  619.         return 0
  620.     }
  621.     return 1
  622. }
  623.  
  624. ###############################################################################
  625. # GetLogCanonicalDate
  626. #    This procedure changes the given date to seconds
  627. #
  628. # Parameter:
  629. #    size: The date in human format
  630. #
  631. # Returns:
  632. #     The date in seconds.
  633. ###############################################################################
  634. proc GetLogCanonicalDate {date} {
  635.     global labelMonths
  636.  
  637.     regexp {([^-]*)(?:-)([^-]*)(?:-)([^-]*)(?:--)?(.*)} \
  638.             $date  nada day  month  year  hour
  639.  
  640.     if {![info exists hour]} {
  641.         set date [clock scan $labelMonths($month)/$day/$year]
  642.     } else {
  643.         set date [clock scan "$labelMonths($month)/$day/$year $hour"]
  644.     }
  645.  
  646.     return $date
  647. }
  648.  
  649. ###############################################################################
  650. # GetLogSortDate
  651. #    This procedure is used to sort the list depending on the downloading date.
  652. #
  653. # Parameter:
  654. #    firstDate, secondDate: The dates to compare
  655. #
  656. # Returns:
  657. #     '-1', '0' or '1' if the first date is earlier than, equal to or later
  658. #     than the second.
  659. ###############################################################################
  660. proc GetLogSortDate {firstDate secondDate} {
  661.  
  662.     set first  [GetLogCanonicalDate $firstDate]
  663.     set second [GetLogCanonicalDate $secondDate]
  664.  
  665.     if {$first<$second} {
  666.         return -1
  667.     } elseif {$first==$second} {
  668.         return 0
  669.     }
  670.     return 1
  671. }
  672.  
  673. ###############################################################################
  674. # GetLogCanonicalSize
  675. #    This procedure changes the given size to bytes
  676. #
  677. # Parameter:
  678. #    size: The size in human format (32,45K , 8.23M, ...)
  679. #
  680. # Returns:
  681. #     The size in bytes.
  682. ###############################################################################
  683. proc GetLogCanonicalSize {size} {
  684.  
  685.     # In case we are using the ',' as decimal separator:
  686.     regsub , $size  {.} size
  687.  
  688.     if {[regexp {(.*)(K)} $size nada size]} {
  689.         set size [expr $size * 1024]
  690.     } elseif {[regexp {(.*)(M)} $size nada size]} {
  691.         set size [expr $size * 1024 * 1024]
  692.     } else {
  693.         regexp {(.*)(B)} $size nada size
  694.     }
  695.  
  696.     return $size
  697. }
  698.  
  699. ###############################################################################
  700. # GetLogSortSize
  701. #    This procedure is used to sort the list depending on the size of the
  702. #    files.
  703. #
  704. # Parameter:
  705. #    firstSize, secondSize The sizes to compare
  706. #
  707. # Returns:
  708. #     '-1', '0' or '1' if the first size is smaller than, equal to or bigger
  709. #     than the second.
  710. ###############################################################################
  711. proc GetLogSortSize {firstSize secondSize} {
  712.  
  713.     set firstSize  [GetLogCanonicalSize $firstSize]
  714.     set secondSize [GetLogCanonicalSize $secondSize]
  715.  
  716.     if {$firstSize<$secondSize} {
  717.         return -1
  718.     } elseif {$firstSize==$secondSize} {
  719.         return 0
  720.     }
  721.     return 1
  722. }
  723.  
  724. ###############################################################################
  725. # GetLogWindowRow
  726. #    Puts one row in the log window.
  727. ###############################################################################
  728. proc GetLogWindowRow {url dir {index end}} {
  729.     global labelMonths labelDialogs
  730.     variable siteLog
  731.     variable urlLog
  732.  
  733.     set month $labelMonths([clock format $urlLog($url,date) -format %m])
  734.  
  735.     # This is a workaround, in Tcl8.4a3 if I write '-format "%d-$month-%Y"'
  736.     # unicode characters in '$month' get mangled.
  737.     set date0 [clock format $urlLog($url,date) -format "%d"]
  738.     set date1 [clock format $urlLog($url,date) -format "%Y"]
  739.     set date  "$date0-$month-$date1"
  740.  
  741.     set tmp [$siteLog(listbox) yview]
  742.     $siteLog(listbox) insert $index [list $url [file nativename $dir] $date]
  743.     if {([lindex $tmp 1]==1)||([lindex $tmp 0]==0)} {
  744.         $siteLog(listbox) yview  $index
  745.     }
  746.  
  747.     return
  748. }
  749.  
  750. ###############################################################################
  751. # GetLogWindowPopulate
  752. #    Puts the urls in the log in the listbox widget.
  753. ###############################################################################
  754. proc GetLogWindowPopulate {} {
  755.     variable urlLog
  756.     variable siteLog
  757.  
  758.     foreach url $urlLog(urlList) {
  759.         catch {GetLogWindowRow $url $urlLog($url,localDir)}
  760.     }
  761.     $siteLog(listbox) yview  0
  762.     return
  763. }
  764.  
  765. ###############################################################################
  766. # GetLogWindow
  767. #    Creates the toplevel window with the site log in it.
  768. ###############################################################################
  769. proc GetLogWindow {} {
  770.     global dirGetleft labelDialogs labelTitles labelMenus getleftOptions
  771.     global indexMenus
  772.     variable siteLog
  773.     variable siteMenus
  774.  
  775.     if {[winfo exists .getLogWindow]} {
  776.         set windowState [wm state .getLogWindow]
  777.         if {$windowState=="withdrawn"} {
  778.             wm deiconify .getLogWindow
  779.         }
  780.         raise $siteLog(toplevel) .
  781.         focus $siteLog(listbox)
  782.         return
  783.     }
  784.  
  785.     set coord(x) [winfo rootx .]
  786.     set coord(y) [winfo rooty .]
  787.  
  788.     set win [toplevel .getLogWindow]
  789.     wm title $win $labelTitles(getLog)
  790.     wm geometry  $win +[expr {$coord(x)+100}]+[expr {$coord(y)+15}]
  791.  
  792.     set extFrame [frame $win.extFrame]
  793.     set intFrame [frame $extFrame.intFrame]
  794.  
  795.     set taskbarFrame [frame $intFrame.taskbarFrame]
  796.     set logFrame     [frame $intFrame.logFrame -bd 2 -relief sunken]
  797.  
  798.     set scrollbarY [scrollbar $logFrame.scrolly -orient vertical   \
  799.             -command  [list $logFrame.listbox yview]]
  800.     set scrollbarX [scrollbar $logFrame.scrollx -orient horizontal \
  801.             -command  [list $logFrame.listbox xview]]
  802.  
  803.     set listbox [::tablelist::tablelist $logFrame.listbox          \
  804.             -bd 0 -height 10 -width 90 -stretch all                \
  805.             -fg $getleftOptions(fg) -bg $getleftOptions(bg)        \
  806.             -columns [list 0 $labelDialogs(url)      left          \
  807.                            0 $labelDialogs(localDir) left          \
  808.                            0 $labelDialogs(date)     left]         \
  809.             -showarrow 1 -labelcommand tablelist::sortByColumn     \
  810.             -xscrollcommand "$scrollbarX set"                      \
  811.             -yscrollcommand "$scrollbarY set"                      \
  812.             -stripebg #eff9fa -exportselection 0]
  813.  
  814.     $listbox columnconfigure 0 -sortmode command
  815.     $listbox columnconfigure 0 -sortcommand ::getLog::GetLogSortUrl
  816.     $listbox columnconfigure 1 -sortmode command
  817.     $listbox columnconfigure 1 -sortcommand ::getLog::GetLogSortUrl
  818.     $listbox columnconfigure 2 -sortmode command
  819.     $listbox columnconfigure 2 -sortcommand ::getLog::GetLogSortDate
  820.  
  821.     set siteLog(toplevel) $win
  822.     set siteLog(listbox)  $listbox
  823.  
  824.     DefineTaskbarButtons $taskbarFrame
  825.  
  826.     pack $extFrame -padx 10 -pady 10 -expand true -fill both
  827.     pack $intFrame -expand true -fill both
  828.     pack $taskbarFrame -padx 2  -fill x
  829.     pack $logFrame -expand true -fill both
  830.     grid $scrollbarY -in $logFrame -row 0 -column 1 -sticky ns
  831.     grid $scrollbarX -in $logFrame -row 1 -column 0 -sticky ew
  832.     grid $listbox    -in $logFrame -row 0 -column 0 -sticky news \
  833.             -padx 0 -pady 0
  834.  
  835.     grid columnconfigure $logFrame 0 -weight 1
  836.     grid columnconfigure $logFrame 1 -weight 0
  837.     grid rowconfigure    $logFrame 0 -weight 1
  838.     grid rowconfigure    $logFrame 1 -weight 0
  839.  
  840.     focus [$listbox bodypath]
  841.  
  842.     bind [$listbox bodypath] <ButtonRelease-1> "
  843.         getLog::ActivateSiteTaskbarButtons
  844.         focus [$listbox bodypath]
  845.     "
  846.     bind [$listbox bodypath] <<Button3>> {
  847.         event generate %W <Button-1>        -x %x -y %y
  848.         event generate %W <ButtonRelease-1> -x %x -y %y
  849.         getLog::UrlLogRightClick %W %x %y %X %Y
  850.     }
  851.     bind [$listbox bodypath] <Double-Button-1> {
  852.         getLog::UrlLogDoubleClick %W %x %y %X %Y
  853.     }
  854.     bind [$listbox bodypath] <FocusIn> {
  855.         $getLog::siteLog(listbox) selection set active
  856.         ActivateSiteTaskbarButtons
  857.     }
  858.     bind [$listbox bodypath] <FocusIn> {
  859.         $getLog::siteLog(listbox) selection clear 0 end
  860.         $getLog::siteLog(listbox) selection set active
  861.     }
  862.     bind [$listbox bodypath] <KeyRelease-Next> {
  863.         $getLog::siteLog(listbox) selection clear 0 end
  864.         $getLog::siteLog(listbox) selection set active
  865.     }
  866.     bind [$listbox bodypath] <KeyRelease-Prior> {
  867.         $getLog::siteLog(listbox) selection clear 0 end
  868.         $getLog::siteLog(listbox) selection set active
  869.     }
  870.     bind $win <Key-Delete> {
  871.         getLog::UrlLogRemove [getLog::UrlLogSelectedUrl]
  872.         $getLog::siteLog(listbox) selection set active
  873.     }
  874.     bind $win <<MenuKey>>  {getLog::UrlLogMenuKey %X %Y}
  875.     bind $win <Escape>     "destroy $win"
  876.  
  877.     set siteMenus(rightClick) [menu $win.menur -tearoff 0]
  878.     $siteMenus(rightClick) add command -label $labelMenus(download)    \
  879.             -underline $indexMenus(download)
  880.     $siteMenus(rightClick) add command -label $labelMenus(update)      \
  881.             -underline $indexMenus(update)
  882.     $siteMenus(rightClick) add separator
  883.     $siteMenus(rightClick) add command -label $labelMenus(queue)       \
  884.             -underline $indexMenus(queue)
  885.     $siteMenus(rightClick) add separator
  886.     $siteMenus(rightClick) add command -label $labelMenus(options)     \
  887.             -underline $indexMenus(options)
  888.     $siteMenus(rightClick) add command -label $labelMenus(localDir)    \
  889.             -underline $indexMenus(localDir)
  890.     $siteMenus(rightClick) add check   -label $labelMenus(notErase)    \
  891.             -underline $indexMenus(notErase)
  892.     $siteMenus(rightClick) add separator
  893.     $siteMenus(rightClick) add command -label $labelMenus(copyLink)    \
  894.             -underline $indexMenus(copyLink)
  895.     $siteMenus(rightClick) add separator
  896.     $siteMenus(rightClick) add command -label $labelMenus(launchLink)  \
  897.             -underline $indexMenus(launchLink)
  898.     $siteMenus(rightClick) add command -label $labelMenus(seeDown)     \
  899.             -underline $indexMenus(seeDown)
  900.     $siteMenus(rightClick) add separator
  901.     $siteMenus(rightClick) add command -label $labelMenus(delete)      \
  902.             -underline $indexMenus(delete)
  903.  
  904.     set siteMenus(doubleClick) [menu $win.menud -tearoff 0]
  905.     $siteMenus(doubleClick) add command -label $labelMenus(download)   \
  906.             -underline $indexMenus(download)
  907.     $siteMenus(doubleClick) add command -label $labelMenus(update)     \
  908.             -underline $indexMenus(update)
  909.  
  910.     GetLogWindowPopulate
  911.  
  912.     return
  913. }
  914.  
  915. ###############################################################################
  916. # GetLog
  917. #    Procedures that controls what happens with the log, it cares care of 
  918. #    reading it into memory, invoking the procedure to draw the window and
  919. #    whatever else needed.
  920. ###############################################################################
  921. proc GetLog {} {
  922.     variable urlLog
  923.  
  924.     if {![info exists urlLog]} {
  925.         UrlLogRead
  926.     }
  927.  
  928.     GetLogWindow
  929.  
  930.     return
  931. }
  932.  
  933. # When we start Getleft we read the log
  934.  
  935. UrlLogRead
  936.  
  937. # Now comes the log for individual files
  938.  
  939. ################################################################################
  940. # ActivateFileTaskbarButtons
  941. #    Activates or disables the buttons in the taskbar depending on whether
  942. #    there is a row selected.
  943. ################################################################################
  944. proc ActivateFileTaskbarButtons {} {
  945.     variable fileTaskbar
  946.     variable fileLog
  947.  
  948.     set anchor [$fileLog(listbox) curselection]
  949.     if {$anchor==""} {
  950.         $fileTaskbar(start) configure -state disabled
  951.     } else {
  952.         $fileTaskbar(start) configure -state normal
  953.     }
  954.  
  955.     set size [$fileLog(listbox) size]
  956.     if {$size==0} {
  957.         $fileTaskbar(clear) configure -state disabled
  958.     } else {
  959.         $fileTaskbar(clear) configure -state normal
  960.     }
  961.  
  962.     return
  963. }
  964.  
  965. ################################################################################
  966. # FileLogRemove
  967. #    Removes one Url from the log 
  968. #
  969. # Parameters
  970. #    url: The url to remove.
  971. ################################################################################
  972. proc FileLogRemove {} {
  973.     variable fileLog
  974.  
  975.     set anchor [$fileLog(listbox) curselection]
  976.     if {$anchor==""} return
  977.  
  978.     $fileLog(listbox) delete $anchor
  979.     $fileLog(listbox) selection set $anchor
  980.     ActivateFileTaskbarButtons
  981.  
  982.     return
  983. }
  984.  
  985. ################################################################################
  986. # FileLogContextMenu
  987. #   This procedure is invoked when the user right-clicks in the multicolumn
  988. #   list with the files, it makes a context menu pop up with the
  989. #   appropiate options
  990. #
  991. # Parameters
  992. #   win: window where you right-clicked.
  993. #   y,x: the coordinates where you did it for the tablelist widget.
  994. #   X,Y: and for the pop up menu.
  995. ################################################################################
  996. proc FileLogContextMenu {X Y} {
  997.     variable fileLog
  998.     variable fileMenus
  999.  
  1000.     set url [FileLogSelectedUrl]
  1001.     if {$url==""} return
  1002.     set ref [FileLogSelectedRef]
  1003.  
  1004.     ActivateFileTaskbarButtons
  1005.  
  1006.     $fileMenus(rightClick) entryconfigure 0                                   \
  1007.             -command "getLog::FileLogDownload [list $url]"
  1008.     $fileMenus(rightClick) entryconfigure 2                                   \
  1009.             -command "clipboard clear
  1010.                       clipboard append [list $url]"
  1011.     $fileMenus(rightClick) entryconfigure 4                                   \
  1012.             -command "Ayuda::InvokeBrowser [list $url] $getLog::fileLog(win)"
  1013.     $fileMenus(rightClick) entryconfigure 5                                   \
  1014.             -command "Ayuda::InvokeBrowser [list $ref] $getLog::fileLog(win)"
  1015.     $fileMenus(rightClick) entryconfigure 7                                   \
  1016.             -command "getLog::FileLogRemove"
  1017.  
  1018.     tk_popup $fileMenus(rightClick) $X $Y
  1019.  
  1020.     return
  1021. }
  1022.  
  1023. ################################################################################
  1024. # FileLogSelectedUrl
  1025. #   When the user clicks on the icons, this procedure is used to know the url
  1026. #   of the row that was selected at the time.
  1027. #
  1028. # Returns
  1029. #   The url or an empty string if no row is selected
  1030. ################################################################################
  1031. proc FileLogSelectedUrl {} {
  1032.     variable fileLog
  1033.  
  1034.     set anchor [$fileLog(listbox) curselection]
  1035.     if {[catch {$fileLog(listbox) cellcget $anchor,1 -text} url]} {
  1036.         return
  1037.     }
  1038.     return $url
  1039. }
  1040.  
  1041. ################################################################################
  1042. # FileLogSelectedRef
  1043. #   When the user clicks on the icons, this procedure is used to know the 
  1044. #   referrer of the url of the row that was selected at the time.
  1045. #
  1046. # Returns
  1047. #   The referrer or an empty string if no row is selected
  1048. ################################################################################
  1049. proc FileLogSelectedRef {} {
  1050.     variable fileLog
  1051.  
  1052.     set anchor [$fileLog(listbox) curselection]
  1053.     if {[catch {$fileLog(listbox) cellcget $anchor,3 -text} ref]} {
  1054.         return
  1055.     }
  1056.     if {$ref!="-"} {
  1057.         return $ref
  1058.     }
  1059.     return        
  1060. }
  1061.  
  1062. ################################################################################
  1063. # FileLogDownload
  1064. #   Ask for a directory and starts downloading the given url.
  1065. ################################################################################
  1066. proc FileLogDownload {url} {
  1067.     variable fileLog
  1068.  
  1069.     if {$url==""} return
  1070.  
  1071.     EnterUrl::EnterUrl 0 $fileLog(win) $url 
  1072.  
  1073.     return
  1074. }
  1075.  
  1076. ################################################################################
  1077. # FileLogDefineTaskbarButtons
  1078. #    Defines the buttons in the taskbar.
  1079. #
  1080. # Parameters
  1081. #    The frame for the buttons.
  1082. ################################################################################
  1083. proc FileLogDefineTaskbarButtons {frame} {
  1084.     global   labelDialogs labelMenus labelButtons
  1085.     variable fileTaskbar
  1086.     variable fileLog
  1087.  
  1088.     set fileTaskbar(start)  [button $frame.start -image $iconNS::iconImages(start) \
  1089.             -relief flat -bd 1 -command {
  1090.                 getLog::FileLogDownload [getLog::FileLogSelectedUrl]
  1091.             }]
  1092.     ::BalloonHelp::set_balloon $fileTaskbar(start)  $labelDialogs(start)
  1093.  
  1094.     set fileTaskbar(clear) [button $frame.clear  -image $iconNS::iconImages(clear) \
  1095.             -relief flat -bd 1 -command "getLog::FileLogClear"]
  1096.     ::BalloonHelp::set_balloon $fileTaskbar(clear)  $labelButtons(clear)
  1097.  
  1098.     set fileTaskbar(exit) [button $frame.exit    -image $iconNS::iconImages(exit)  \
  1099.             -relief flat -bd 1 -command "wm withdraw $fileLog(win)"]
  1100.     ::BalloonHelp::set_balloon $fileTaskbar(exit)   $labelDialogs(exit)
  1101.  
  1102.     foreach {name path} [array get fileTaskbar] {
  1103.         bindtags $path "[bindtags $path] logTaskIcon"
  1104.     }
  1105.     bind logTaskIcon <<ButtonRaise>> {
  1106.         %W configure -relief raised
  1107.     }
  1108.     bind logTaskIcon <<ButtonFlat>> {
  1109.         %W configure -relief flat
  1110.     }
  1111.     pack $fileTaskbar(start) $fileTaskbar(clear) -side left
  1112.     pack $fileTaskbar(exit)  -side right
  1113.  
  1114.     return
  1115. }
  1116.  
  1117. ###############################################################################
  1118. # FileLogEnter
  1119. #    Logs in the file 'fileDown.log' the error messages returned by 'curl'
  1120. #
  1121. # Parameters
  1122. #    message: The error message.
  1123. #    link: link that we where trying to download.
  1124. #    referer: Referrer page of that link.
  1125. #    size:    The size of the downloaded file.
  1126. ###############################################################################
  1127. proc FileLogEnter {message link referer {size ""}} {
  1128.     global dirGetleft getleftState
  1129.     global labelDialogs labelMonths labelCurlCodes 
  1130.     global errorCode supportedLang getleftOptions
  1131.     variable fileLog 
  1132.  
  1133.     if {[regexp {[0-9]+} $message]} {
  1134.         catch {set message $labelCurlCodes($message)}
  1135.     }
  1136.  
  1137.     set seconds [clock seconds]
  1138.     set month $labelMonths([clock format $seconds -format %m])
  1139.  
  1140.     # This is a workaround, in Tcl8.4a3 if I write '-format "%d-$month-%Y"'
  1141.     # unicode characters in '$month' get mangled.
  1142.     set date0 [clock format $seconds -format "%d"]
  1143.     set date1 [clock format $seconds -format "%Y -- %H:%M"]
  1144.     set date  "$date0-$month-$date1"
  1145.  
  1146.     if {$size!=""} {
  1147.         if {$size<512} {
  1148.             set size ${size}B
  1149.         } elseif {$size<1048576} {
  1150.             set size "[format "%.2f" [expr {$size/1024.0}]]K"
  1151.         } else {
  1152.             set size "[format "%.2f" [expr {$size/1048576.0}]]M"
  1153.         }
  1154.         regsub {\.} $size $labelDialogs(decimal) size
  1155.     }
  1156.  
  1157.     set fileLog(file) [file join $dirGetleft(conf) fileDown.log]
  1158.     if {$getleftState(os)=="win"} {
  1159.         if {[file exists $fileLog(file)]} {
  1160.             file attributes $fileLog(file) -hidden 0
  1161.         }
  1162.     } 
  1163.     set handle  [open $fileLog(file) a+]
  1164.     fconfigure $handle -encoding $supportedLang($getleftOptions(lang))
  1165.  
  1166.     # Some of these variables maybe empty, others may have spaces so we
  1167.     # put them between quotes.
  1168.     puts $handle "\"$message\" \"$link\" \"$size\" \"$referer\" \"$date\""
  1169.  
  1170.     close $handle
  1171.  
  1172.     if {$getleftState(os)=="win"} {
  1173.         file attributes $fileLog(file) -hidden 1
  1174.     } else {
  1175.         file attributes $fileLog(file) -permissions 0600
  1176.     }
  1177.  
  1178.     if {([info exists fileLog(win)])&&([winfo exists $fileLog(win)])} {
  1179.         set tmp [$fileLog(listbox) yview]
  1180.         $fileLog(listbox) insert end [list $message $link $size $referer $date]
  1181.         if {([lindex $tmp 1]==1)||([lindex $tmp 0]==0)} {
  1182.             $fileLog(listbox) yview moveto 1
  1183.         }
  1184.     }
  1185.     if {([info exists fileLog(win)])&&([winfo exists $fileLog(win)])} {
  1186.         ActivateFileTaskbarButtons
  1187.     }
  1188.  
  1189.     return
  1190. }
  1191.  
  1192. ###############################################################################
  1193. # EraseErrorClear
  1194. #    Deletes the error log and clears the listbox.
  1195. ###############################################################################
  1196. proc FileLogClear {} {
  1197.     global dirGetleft labelTitles labelMessages
  1198.     variable fileLog
  1199.  
  1200.     set what [tk_messageBox -title "$labelTitles(sure)" -parent $fileLog(win) \
  1201.             -message "$labelMessages(clearLog)" -type yesno]
  1202.     if {$what=="no"} {
  1203.         return
  1204.     }
  1205.  
  1206.     $fileLog(listbox) delete 0 end
  1207.     catch {file delete $fileLog(file)}
  1208.  
  1209.     ActivateFileTaskbarButtons
  1210.  
  1211.     return
  1212. }
  1213.  
  1214. ###############################################################################
  1215. # FileLogScroll
  1216. #    Scrolls the text up or down a third of its height
  1217. #
  1218. # Parameters
  1219. #    text: full path of the text widget
  1220. #    how:  either 'up' or 'down'
  1221. ###############################################################################
  1222. proc FileLogScroll {text how} {
  1223.  
  1224.     set height [$text cget -height]
  1225.     set scroll [expr {round ($height/2.5)}]
  1226.     if {$how=="up"} {
  1227.         set scroll [expr {$scroll * -1}]
  1228.     }
  1229.  
  1230.     $text yview scroll $scroll units
  1231.  
  1232.     return
  1233. }
  1234.  
  1235. ###############################################################################
  1236. # FileLog
  1237. #   Shows a window with  the contents of the file log.
  1238. ###############################################################################
  1239. proc FileLog {} {
  1240.     global labelButtons labelTitles labelMessages labelDialogs labelMenus
  1241.     global dirGetleft supportedLang getleftOptions indexMenus
  1242.     variable fileLog
  1243.     variable fileMenus
  1244.  
  1245.     if {[winfo exists .fileLog]} {
  1246.         set windowState [wm state .fileLog]
  1247.         if {$windowState=="withdrawn"} {
  1248.             wm deiconify .fileLog
  1249.         }
  1250.         raise $fileLog(win)
  1251.         focus $fileLog(listbox)
  1252.         return
  1253.     }
  1254.  
  1255.     set fileLog(file) [file join "$dirGetleft(conf)" fileDown.log]
  1256.     set formerLog     [file join "$dirGetleft(conf)" Geterror.log]
  1257.     catch {file delete -force $formerLog}
  1258.  
  1259.     set coord(x) [winfo rootx .]
  1260.     set coord(y) [winfo rooty .]
  1261.  
  1262.     set fileLog(win) [toplevel .fileLog]
  1263.     wm title $fileLog(win) $labelTitles(getLog)
  1264.     wm geometry $fileLog(win) +[expr {$coord(x)+100}]+[expr {$coord(y)+50}]
  1265.  
  1266.     set extFrame     [frame $fileLog(win).ext]
  1267.     set intFrame     [frame $extFrame.int]
  1268.     set taskBarFrame [frame $intFrame.taskBar]
  1269.     set logFrame     [frame $intFrame.log -bd 2 -relief sunken]
  1270.  
  1271.     set scrollBars(y) [scrollbar $intFrame.yscroll -orient vertical     \
  1272.             -command [list $logFrame.listbox yview] ]
  1273.     set scrollBars(x) [scrollbar $intFrame.xscroll -orient horizontal   \
  1274.             -command [list $logFrame.listbox xview] ]
  1275.  
  1276.     set fileLog(listbox) [::tablelist::tablelist $logFrame.listbox      \
  1277.             -bd 0 -height 10 -width 120 -stretch all                    \
  1278.             -fg $getleftOptions(fg) -bg $getleftOptions(bg)             \
  1279.             -columns [list 0 $labelDialogs(code)     left               \
  1280.                            0 $labelDialogs(url)      left               \
  1281.                            0 $labelDialogs(size)     right              \
  1282.                            0 $labelDialogs(referer)  left               \
  1283.                            0 $labelDialogs(date)     left]              \
  1284.             -showarrow 1 -labelcommand tablelist::sortByColumn          \
  1285.             -xscrollcommand "$scrollBars(x) set"                        \
  1286.             -yscrollcommand "$scrollBars(y) set"                        \
  1287.             -stripebg #eff9fa -exportselection 0]
  1288.  
  1289.     $fileLog(listbox) columnconfigure 0 -labelalign center
  1290.     $fileLog(listbox) columnconfigure 2 -labelalign center
  1291.  
  1292.     $fileLog(listbox) columnconfigure 1 -sortmode command
  1293.     $fileLog(listbox) columnconfigure 1 -sortcommand ::getLog::GetLogSortUrl
  1294.     $fileLog(listbox) columnconfigure 2 -sortmode command
  1295.     $fileLog(listbox) columnconfigure 2 -sortcommand ::getLog::GetLogSortSize
  1296.     $fileLog(listbox) columnconfigure 3 -sortmode command
  1297.     $fileLog(listbox) columnconfigure 3 -sortcommand ::getLog::GetLogSortUrl
  1298.     $fileLog(listbox) columnconfigure 4 -sortmode command
  1299.     $fileLog(listbox) columnconfigure 4 -sortcommand ::getLog::GetLogSortDate
  1300.  
  1301.     pack $extFrame -padx 10 -pady 10 -expand true -fill both
  1302.     pack $intFrame -expand true -fill both
  1303.     pack $taskBarFrame -padx 2  -fill x
  1304.     pack $logFrame -expand true -fill both
  1305.  
  1306.     FileLogDefineTaskbarButtons $taskBarFrame
  1307.  
  1308.     grid $scrollBars(y)     -in $logFrame -row 0 -column 1 -sticky ns
  1309.     grid $scrollBars(x)     -in $logFrame -row 1 -column 0 -sticky ew
  1310.     grid $fileLog(listbox)  -in $logFrame -row 0 -column 0 -sticky news \
  1311.             -padx 0 -pady 0
  1312.  
  1313.     grid columnconfigure $logFrame 0 -weight 1
  1314.     grid columnconfigure $logFrame 1 -weight 0
  1315.     grid rowconfigure    $logFrame 0 -weight 1
  1316.     grid rowconfigure    $logFrame 1 -weight 0
  1317.  
  1318.     bind $fileLog(win) <Escape>    "destroy $fileLog(win)"
  1319.     bind $fileLog(win) <<MenuKey>> "getLog::FileLogContextMenu %X %Y"
  1320.  
  1321.     bind [$fileLog(listbox) bodypath] <ButtonRelease-1> "
  1322.         getLog::ActivateFileTaskbarButtons
  1323.         focus [$fileLog(listbox) bodypath]
  1324.     "
  1325.     bind [$fileLog(listbox) bodypath] <Double-Button-1> {
  1326.         getLog::FileLogDownload [getLog::FileLogSelectedUrl]
  1327.     }
  1328.     bind [$fileLog(listbox) bodypath] <<Button3>> {
  1329.         event generate %W <Button-1>        -x %x -y %y
  1330.         event generate %W <ButtonRelease-1> -x %x -y %y
  1331.         getLog::FileLogContextMenu %X %Y
  1332.     }
  1333.     bind [$fileLog(listbox) bodypath] <Key-Delete> {
  1334.         getLog::FileLogRemove
  1335.         $getLog::fileLog(listbox) selection set active
  1336.     }
  1337.     bind [$fileLog(listbox) bodypath] <FocusIn> {
  1338.         $getLog::fileLog(listbox) selection clear 0 end
  1339.         $getLog::fileLog(listbox) selection set active
  1340.         getLog::ActivateFileTaskbarButtons
  1341.     }
  1342.     bind [$fileLog(listbox) bodypath] <KeyRelease-Next> {
  1343.         $getLog::fileLog(listbox) selection clear 0 end
  1344.         $getLog::fileLog(listbox) selection set active
  1345.     }
  1346.     bind [$fileLog(listbox) bodypath] <KeyRelease-Prior> {
  1347.         $getLog::fileLog(listbox) selection clear 0 end
  1348.         $getLog::fileLog(listbox) selection set active
  1349.     }
  1350.  
  1351.     focus [$fileLog(listbox) bodypath]
  1352.  
  1353.  
  1354.     set fileMenus(rightClick) [menu $fileLog(win).menur -tearoff 0]
  1355.     $fileMenus(rightClick) add command -label $labelMenus(download)        \
  1356.             -underline $indexMenus(download)
  1357.     $fileMenus(rightClick) add separator
  1358.     $fileMenus(rightClick) add command -label $labelMenus(copyLink)        \
  1359.             -underline $indexMenus(copyLink)
  1360.     $fileMenus(rightClick) add separator
  1361.     $fileMenus(rightClick) add command -label $labelMenus(launchLink)      \
  1362.             -underline $indexMenus(launchLink)
  1363.     $fileMenus(rightClick) add command -label $labelMenus(launchRef)       \
  1364.             -underline $indexMenus(launchRef)
  1365.     $fileMenus(rightClick) add separator
  1366.     $fileMenus(rightClick) add command -label $labelMenus(delete)          \
  1367.             -command "getLog::FileLogRemove" -underline $indexMenus(delete)
  1368.  
  1369.     if {![file exists $fileLog(file)]} {
  1370.         return
  1371.     }
  1372.     if {[catch {open $fileLog(file) r} handle]} {
  1373.         return
  1374.     }
  1375.     fconfigure $handle -encoding $supportedLang($getleftOptions(lang))
  1376.  
  1377.     for {} {![eof $handle]} {} {
  1378.         set line [gets $handle]
  1379.         if {$line!=""} {
  1380.             catch {$fileLog(listbox) insert end $line}
  1381.         }
  1382.     }
  1383.  
  1384.     close $handle
  1385.     ActivateFileTaskbarButtons
  1386.  
  1387.     return
  1388. }
  1389.  
  1390. }
  1391.  
  1392.  
  1393.